import React, { Component, createRef } from 'react'
import {ADD_TODO} from './store/types'
import { connect } from 'react-redux'
class Header extends Component {

  inpRef = createRef()

  render() {
    return (
      <div className='header'>
          <input ref={this.inpRef} type="text" placeholder='请输入待办事件' />
          <button onClick={()=>{
            console.log(this.inpRef.current.value);

            // 需要添加的对象
            const obj = {
              title: this.inpRef.current.value,
              isSelect: false,
              id: String(Math.random())
            }

            this.props.addItem(obj)

            this.inpRef.current.value = ''
          }}> 提交 </button>
      </div>
    )
  }
}

export default connect(null,(dispatch)=>{
  return {
    addItem(obj){
      dispatch({type: ADD_TODO, payload: obj})
    }
  }
})(Header)
